#Include <..\include\Common_For_PageManager.au3>
#Include <GuiButton.au3>

AutoItSetOption("MustDeclareVars", 1)   ;Variables must be pre-declared.
 
Dim Const $sCorrectResultPath = "C:\Print\Correct Resut\"  
Dim Const $sTestResultPath = "C:\Print\Perform Result\"  
Dim Const $sSampleFolderPath = "C:\Print\Sample\" 
Dim Const $iNumber = Common_GetNumberInExcelSheet($oExcel,$sPrintFunctionName)  
Dim Const $iCurrentSheetTotalLineNumber = $iNumber[0]   ;Get all number of rows in current excel sheet.
Dim Const $sFunctionFolderPath = "C:\Print\"  
Dim Const $CommonWindowCtrlInfro = ''
Dim Const $PrintFaxSetupDialogTitle = "Print/Fax Setup"
Global Const $sExcelSheetName = 'Print'
Global Const $iRescolumn = 14
Global $sCusMsg = ''
Global $sFailLogMsg = ''
Dim Const $sEditMenuHotKey 						= ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'EditMenuHotKey')
Dim Const $sToolsMenuHotKey 					= ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'ToolsMenu')
Dim Const $sViewMenuHotKey 						= ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'ViewMenuHotKey')
Dim Const $sFileMenuHotKey 						= ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'FileMenuHotKey')
Dim Const $sAnnotationBarCtrlInfo 				= ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'AnnotationBar')
Dim Const $DocumentPallet 						= ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'DocumentPallet')
Dim Const $sTileButtonInToolBarCtrlInfo 		= Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'TileButtonInToolBar'))
Dim Const $sApplication_Properties 				= ReadIniKeyValue($sPCodeIniPath, $sSectionNameFax, 'Application_Properties')
Dim Const $sSetup_Button 						= Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameFax, 'Setup_Button'))
Dim Const $sPrint_Dialog_Title 					= ReadIniKeyValue($sPCodeIniPath, $sSectionNameFax, 'Print_Dialog')
Dim Const $sAlertMessage_EmptyFileNameForSaveAs = ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'AlertMessage_EmptyFileNameForSaveAs')
Global $msg = 'Check print file'
Func AddAnnotation($hPMHandle)
		;Add stamp annotation in page view.
	Local $sReturn = Common_ControlGetPos($hPMHandle, "", $sAnnotationBarCtrlInfo)
	MouseMove($sReturn[0] + $sReturn[2]/2,$sReturn[1] + $sReturn[3]/4.2)
	Common_SleepTime(1)
	MouseClick('left',$sReturn[0] + $sReturn[2]/2,$sReturn[1] + $sReturn[3]/4.2)
	Send('{DOWN}')
	Common_SleepTime(1)
	Send('{ENTER}')
	Local $sReturn = Common_ControlGetPos($hPMHandle, "", $sThumbnailViewCtrInfo)
	MouseClick('left', $sReturn[0] + $sReturn[2]/3.6, $sReturn[1] + $sReturn[3]/2.6)
	Common_SleepTime(2)
	ControlClick($hPMHandle, "", $sSwicthToThumbnailViewButtonCtrInfo)   ;Click thumbnail button.
	Send('{ENTER}')   ;Save anonotaton.	
EndFunc


Func SetOrientation($sSize)
	ControlClick($CommonWindowCtrlInfro,"",14009)   ;Setup 
	Common_SleepTime(4) 
	ControlClick($CommonWindowCtrlInfro,"",1025)   ;Properties...
	Common_SleepTime(4) 
	Switch $sSize
	Case "Portrait"
		ControlCommand($CommonWindowCtrlInfro,"",23005,"Check", "")
	Case "Landscape"
		ControlCommand($CommonWindowCtrlInfro,"",23007,"Check", "")		
	EndSwitch
	Common_SleepTime(1)	
	ControlClick($CommonWindowCtrlInfro,"",1)
	Common_SleepTime(4) 
	ControlClick($CommonWindowCtrlInfro,"",1)
	Common_SleepTime(4)
	ControlClick($CommonWindowCtrlInfro,"",1)
	Common_SleepTime(4)	
EndFunc	


Func SetPaperSize($sSize)
	ControlClick($CommonWindowCtrlInfro,"",14009)   ;Setup 
	Common_SleepTime(4) 
	ControlClick($CommonWindowCtrlInfro,"",1025)   ;Properties...
	Common_SleepTime(4) 
	Switch $sSize
	Case "Letter"
		ControlCommand($CommonWindowCtrlInfro,"",23003,"SelectString", 'Letter')
	Case "Legal"
		ControlCommand($CommonWindowCtrlInfro,"",23003,"SelectString", 'Legal')
	Case "A4"
		ControlCommand($CommonWindowCtrlInfro,"",23003,"SelectString", 'A4')		
	Case "A5"
		ControlCommand($CommonWindowCtrlInfro,"",23003,"SelectString", 'A5')			
	EndSwitch
	Common_SleepTime(1)	
	ControlClick($CommonWindowCtrlInfro,"",1)
	Common_SleepTime(4) 
	ControlClick($CommonWindowCtrlInfro,"",1)
	Common_SleepTime(4)
	ControlClick($CommonWindowCtrlInfro,"",1)
	Common_SleepTime(4)	
EndFunc	




Func OrininalSize()
	ControlCommand($CommonWindowCtrlInfro,"",14011,"Check", "")
	Sleep(300)
	ControlClick($CommonWindowCtrlInfro,"",1)
	Common_SleepTime(3) 	
EndFunc

Func PrintSetting($s)
	Switch $s
	Case 'OrininalSize'
		ControlCommand($CommonWindowCtrlInfro,"",14011,"Check", "")
	Case 'Fit to Page'
		ControlCommand($CommonWindowCtrlInfro,"",14012,"Check", "")
	Case 'Halftone Image'
		ControlCommand($CommonWindowCtrlInfro,"",14013,"Check", "")
	Case 'Diffuse'
		ControlCommand($CommonWindowCtrlInfro,"",14014,"Check", "")
	EndSwitch
	Sleep(300)
	ControlClick($CommonWindowCtrlInfro,"",1)
	Common_SleepTime(3) 	
EndFunc

Func InitializeStatusForPrint()
	Local $FileList = _FileListToArray ($sFunctionFolderPath,"*", 1)
	If Not @error Then
		If $FileList[0] >= 1 Then
			For $i = 1 to $FileList[0]
				FileDelete ($sFunctionFolderPath & $FileList[$i])
			Next
			Return 1
		EndIf
	EndIf
EndFunc

Func PrintFile($sName)
	WinWaitActive ($CommonWindowCtrlInfro, '', 5)
	WinActivate($CommonWindowCtrlInfro)
	Local $h = ControlGetHandle("[CLASS:#32770]", "FolderView", 23034)
	Local $sState = _GUICtrlButton_GetCheck($h)
	If $sState == 1 Then
		ControlClick("[CLASS:#32770]", "FolderView", 23034)   ;Uncheck when print finished preview  pewview file.
	EndIf
	ControlSetText("[CLASS:#32770]", "FolderView", 1148, $sName)    ;Set file name.
	Common_SleepTime(1)
	ControlClick($CommonWindowCtrlInfro, '', 'Button2')   ;OK button
	Common_SleepTime(4)
EndFunc

Func SelectPrint()
	OpenMenu("File")
	Send("p")
	Sleep(200)
	Send("p")
	Sleep(200)
	Send("{right}")
	Sleep(200)
	Send("{Down}")
	Sleep(200)
	Send("{Down}")
	Sleep(200)
	Send("{Enter}")
	Common_SleepTime(12)	
	WinWaitActive($CommonWindowCtrlInfro, '', 5)
EndFunc	

Func OpenProperties()
	OpenMenu("File")
	Send("u")
	Sleep(200)
	Send("{Down}")
	Sleep(200)
	Send("{Down}")
	Sleep(200)
	Send("{Enter}")
	Common_SleepTime(4)	
	WinWaitActive($CommonWindowCtrlInfro, '', 5)
EndFunc

Func OpenMenu($sMenu)
	Switch $sMenu
	Case "Edit"
		Send("!" & $sEditMenuHotKey)	
		Common_SleepTime(2)	
	Case "Tools"
		Send("!" & $sToolsMenuHotKey)	
		Common_SleepTime(2)	
	Case "View"
		Send("!" & $sViewMenuHotKey)	
		Common_SleepTime(2)	
	Case "File"
		Send("!" & $sFileMenuHotKey)	
		Common_SleepTime(2)
	EndSwitch	
EndFunc

































